package br.com.jsfprimefaces.managerBean;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import br.com.jsfprimefaces.dao.UsuarioDAO;
import br.com.jsfprimefaces.model.*;

@ManagedBean(name="LoginMB")
@SessionScoped
public class LoginMbean implements Serializable{

	private static final long serialVersionUID = 1L;
	
	private String login;
	private String senha;
	private String erro;
	
	public String getLogin() {
		return login;
	}
	public String getErro() {
		return erro;
	}
	public void setErro(String erro) {
		this.erro = erro;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	public String getSenha() {
		return senha;
	}
	public void setSenha(String senha) {
		this.senha = senha;
	}	
	
	public String autentica(){
		Usuario user = new Usuario();
		user.setLogin(login);
		user.setSenha(senha);
		
		UsuarioDAO usuarioDAO = new UsuarioDAO();
		
		if (usuarioDAO.autenticar(user)){
			System.out.println("Login permitido");
			System.out.println(user.getLogin());
			System.out.println(user.getSenha());
			return "/page/menu.xhtml";
		}else{
			setErro("Account or Password, is incorrect!");
			return "/page/index.xhtml";
		}
			
	}
	
	public void teste(){
		System.out.println("- - - - ");
	}
	
	
	
}
